package com.wjy.rbac.controller;

import com.wjy.common.base.controller.BaseController;
import com.wjy.common.result.ResultBuilder;
import com.wjy.rbac.entity.PowerRequestMethod;
import com.wjy.rbac.service.IPowerRequestMethodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ybxxszl
 * @since 2019-04-12
 */
@Log4j2
@Api(tags = "权限请求方式控制")
@RestController
@RequestMapping("/test/powerRequestMethod")
public class PowerRequestMethodController extends BaseController {

    @Autowired
    @Qualifier(value = "powerRequestMethodServiceImpl")
    private IPowerRequestMethodService powerRequestMethodService;

    @ApiOperation(value = "添加权限请求方式")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResultBuilder insert(@RequestBody PowerRequestMethod powerRequestMethod) {
        try {
            powerRequestMethodService.insert(powerRequestMethod);
            return ResultBuilder.success("添加成功");
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return ResultBuilder.error(e);
        }
    }

    @ApiOperation(value = "更新权限请求方式")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResultBuilder update(@RequestBody PowerRequestMethod powerRequestMethod) {
        try {
            powerRequestMethodService.update(powerRequestMethod);
            return ResultBuilder.success("更新成功");
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return ResultBuilder.error(e);
        }
    }

    @ApiOperation(value = "删除权限请求方式")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public ResultBuilder delete(String powerRequestMethodId) {
        try {
            powerRequestMethodService.delete(powerRequestMethodId);
            return ResultBuilder.success("删除成功");
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return ResultBuilder.error(e);
        }
    }

    @ApiOperation(value = "获取权限请求方式")
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public ResultBuilder get(String powerRequestMethodId) {
        try {
            Map<String, Object> map = powerRequestMethodService.get(powerRequestMethodId);
            return ResultBuilder.success(map);
        } catch (Exception e) {
            log.error(e);
            e.printStackTrace();
            return ResultBuilder.error(e);
        }
    }

}
